home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-2 / Inter.Net 55-2.iso / Mandrake / mdkinst / usr / lib / perl5 / 5.00503 / lib.pm < prev    next >
Encoding:
Perl POD Document  |  2000-01-12  |  1.2 KB  |  56 lines

  1. package lib;
  2.  
  3. use vars qw(@ORIG_INC);
  4. use Config;
  5.  
  6. my $archname = $Config{'archname'};
  7.  
  8. @ORIG_INC = @INC;    # take a handy copy of 'original' value
  9.  
  10.  
  11. sub import {
  12.     shift;
  13.     foreach (reverse @_) {
  14.     ## Ignore this if not defined.
  15.     next unless defined($_);
  16.     if ($_ eq '') {
  17.         require Carp;
  18.         Carp::carp("Empty compile time value given to use lib");
  19.                             # at foo.pl line ...
  20.     }
  21.     if (-e && ! -d _) {
  22.         require Carp;
  23.         Carp::carp("Parameter to use lib must be directory, not file");
  24.     }
  25.     unshift(@INC, $_);
  26.     # Put a corresponding archlib directory infront of $_ if it
  27.     # looks like $_ has an archlib directory below it.
  28.     if (-d "$_/$archname") {
  29.         unshift(@INC, "$_/$archname")    if -d "$_/$archname/auto";
  30.         unshift(@INC, "$_/$archname/$]") if -d "$_/$archname/$]/auto";
  31.     }
  32.     }
  33. }
  34.  
  35.  
  36. sub unimport {
  37.     shift;
  38.     my $mode = shift if $_[0] =~ m/^:[A-Z]+/;
  39.  
  40.     my %names;
  41.     foreach(@_) {
  42.     ++$names{$_};
  43.     ++$names{"$_/$archname"} if -d "$_/$archname/auto";
  44.     }
  45.  
  46.     if ($mode and $mode eq ':ALL') {
  47.     # Remove ALL instances of each named directory.
  48.     @INC = grep { !exists $names{$_} } @INC;
  49.     } else {
  50.     # Remove INITIAL instance(s) of each named directory.
  51.     @INC = grep { --$names{$_} < 0   } @INC;
  52.     }
  53. }
  54.  
  55. 1;
  56.